Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

258
Vistas
Why when I set the value of an hidden input to a value of an array of objects it makes every item in the hidden input array into [object Object]

I have this code:

for(let i =0; i < upbtn.length; i++){
  upbtn[i].addEventListener('click', function(){
    let whichTopic = i
    if(whichTopic == 0){
      return true
    }
    else{
      let arr = coursenewtopics.value
      arr = JSON.parse(arr)
      arraymove(arr, i, i-1)
      coursenewtopics.value = arr
      console.log(arr)
      console.log(coursenewtopics.value)
      //changeordertopicsform.submit()
    }
  })
}

I am trying to sort an array from an hidden input then set the value of the hidden input to the sorted array, I console logged the results from the sorted array(arr)

[
    {
        "type": "text",
        "name": "",
        "text": ""
    },
    {
        "type": "text",
        "name": "2",
        "text": ""
    },
    {
        "type": "text",
        "name": "1",
        "text": ""
    },
    {
        "type": "text",
        "name": "3",
        "text": ""
    },
    {
        "type": "text",
        "name": "4",
        "text": ""
    }
]

and the results are what I want, however when after I put this value I just logged of arr to the hidden input, then console log the value of the hidden input becomes:

[object Object],[object Object],[object Object],[object Object],[object Object]

why does JavaScript act this? how do I fix this an put the values into the hidden input without making them go [object Object]? I need them for a form later on.

Thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

so your problem is 'How to display an array of object literally'.

you can try JSON.stringify(arr, null, ' ')

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda